package com.base.cn.platform.os.controller.order.user;

import com.base.cn.platform.os.common.utils.order.PayType;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.manage.order.goods.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户订单接口
 *
 * @author s.li
 * @create 2018-09-05-13:38
 */
@RestController
@RequestMapping("/api/order")
public class ApiUserOrderController extends ApiBaseController {

    @Autowired
    private OrderService orderService;


    /**
     * 获取用户订单列表
     * @param userId 用户ID
     * @param orderStatus 订单状态
     * @param currentPage 页码
     * @return Map<String,Object>
     */
    @RequestMapping("/queryUserOrderList")
    public Map<String,Object> queryUserOrderList(@RequestParam("userId")BigDecimal userId,
                                                 @RequestParam(value = "orderStatus",required = false) String orderStatus,
                                                 @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage){
        Map<String,Object> params = new HashMap<>();
        params.put("userId",userId);
        params.put("status",1);
        params.put("orderStatus",orderStatus);
        params.put("notPayType","'"+ PayType.PAY_TYPE_FREE +"','"+PayType.PAY_TYPE_COURSE_CART+"','"+PayType.PAY_TYPE_MEMBER+"'");
        Map<String,Object> orderMap = orderService.findWebOrderPage(params,currentPage,10,false,true,true,false);
        return ResultUtil.SUCCESS(orderMap);
    }

    @RequestMapping("/cancelOrder")
    public Map<String,Object> cancelOrder(@RequestParam("orderId") BigDecimal orderId){
        return    orderService.cancelOrder(orderId);
    }
}
